import {request} from "../utils/request";

//登录
export async function wx_login(code) {
    const res = await request({
        url: `/wxapp/wxlogin`,
        method: 'POST',
        header:{
            code
        }
    }).catch()
    return res
}

//注册
export async function wx_register(code,data) {
    const res = await request({
        url: `/wxapp/wxlogin/register`,
        method: 'POST',
        header:{
            code
        },
        data
    }).catch()
    return res
}

//获取code码
export function getCode() {
    return new Promise(((resolve, reject) => {
        uni.login({
            provider: 'weixin', //使用微信登录
            success: function (loginRes) {
                resolve(loginRes)
            },
            fail(err){
                resolve(err)
            }
        })
    }))
}

//获取手机号
export async function getPhone(data) {
    const res = await request({
        url: `/wxapp/wxlogin/getphone`,
        method: 'POST',
        header:{
            'content-type':'application/x-www-form-urlencoded'
        },
        data
    }).catch()
    return res
}
